package com.fantasy.servlet;


import com.fantasy.entity.Page;
import com.fantasy.entity.Video;
import com.fantasy.service.VideoService;
import com.fantasy.service.impl.VideoServiceImpl;
import com.fantasy.utils.WebUtils;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;

@WebServlet("/client/search.do")
public class CSearchServlet extends BaseServlet {
    VideoService videoService=new VideoServiceImpl();


    public void page(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String name = request.getParameter("name");
        int pageNo = WebUtils.parseInt(request.getParameter("pageNo"), 1);
        int pageSize = WebUtils.parseInt(request.getParameter("pageSize"), 12);
        Page<Video> page = videoService.ResultPage(name, pageNo, pageSize);

        //基于 Ajax
//        response.setContentType("text/html;charset=utf-8");
//        Gson gson = new Gson();
//        String s=gson.toJson(page);
//        response.getWriter().write(s);

        //基于 JSP
        request.setAttribute("page", page);
        request.setAttribute("name",name);
        request.getRequestDispatcher("/client/search.jsp").forward(request, response);
    }
}
